package com.example.demo.service;


import com.example.demo.dto.AuthLogDTO;
import com.example.demo.dto.LogQueryRequest;
import com.example.demo.dto.LogResponse;
import com.example.demo.entity.AuthLog;
import com.example.mapper.AuthLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class AuthLogService {
    @Autowired
    private AuthLogMapper authLogMapper;
    public LogResponse getLogs(LogQueryRequest request) {
        Integer pageSize = request.getPageSize();
        Integer pageNum = (request.getPageNum() -1 )* pageSize;
        long total;
        List<AuthLog> logList;
        if("all".equals(request.getFilter())){
            logList = authLogMapper.findAll();
            total = authLogMapper.countAll();
        }else{
            logList = authLogMapper.findByFilter(request.getFilter(), pageNum, pageSize);
            total = authLogMapper.countByFilter(request.getFilter());
        }
        LogResponse response = new LogResponse();
        response.setLogList(logList);
        response.setTotal(total);
        return response;
    }
    public List<AuthLogDTO> findAllAuthLogs(){
        return  authLogMapper.findAllAuthLogs();
    }
}